/* eslint-disable no-unused-vars */
const { app, BrowserWindow, Tray } = require('electron')
const path = require('path')

let tray = null;

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 1400,
    height: 900,
    minWidth: 1200,
    minHeight: 800,
    maxWidth: 1400,
    maxHeight: 900,
    icon: path.join(__dirname, '../public/logo192.jpg'),
    autoHideMenuBar: true,
    maximizable: false,  // 禁用最大化按钮
    frame: true, // electron顶部控制器
    webPreferences: {
      devTools: true, // deTool
      nodeIntegration: true,
      contextIsolation: false,
      preload: path.join(__dirname, './preload')
    }
  })

  mainWindow.loadFile('public/index.html')
  mainWindow.loadURL('http://localhost:3001/')

  tray = new Tray(path.join(__dirname, '../public/logo192.jpg'));
  // 打开调试控制台
  // mainWindow.webContents.openDevTools();
}

app.whenReady().then(() => {
  createWindow()
  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

